package utils;

import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ���õĲ�������ʱ��Ĺ���
 * 
 * @Company ��������Ƽ����޹�˾
 * @author QianFei Xu
 */
public final class DateUtils {
	public static final long SECONDS = 1000;
	public static final long MINUTE = SECONDS * 60;
	public static final long HOUR = MINUTE * 60;
	public static final long DAY = HOUR * 24;
	public static final long WEEK = DAY * 7;
	public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
	public static final String DEFAULT_DATE_HH_PATTERN = "yyyy-MM-dd HH";
	public static final String DEFAULT_DATE_HHMM_PATTERN = "yyyy-MM-dd HH mm";
	public static final String DEFAULT_DATE_HH_MM_PATTERN = "yyyy-MM-dd HH:mm";
	public static final String DEFAULT_DATETONUMBER_PATTERN = "yyyyMMdd";
	public static final String DEFAULT_DATEHHTONUMBER_PATTERN = "yyyyMMddHH";
	public static final String DEFAULT_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final String DEFAULT_DATETIMEMILL_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";

	// �ж������Ƿ���ȷ
	public static boolean isExistDate(final int yyyy, final int mm, final int dd) {
		final Calendar cal = Calendar.getInstance();
		cal.set(yyyy, mm - 1, dd);
		return cal.get(Calendar.DATE) == dd && cal.get(Calendar.MONTH) + 1 == mm && cal.get(Calendar.YEAR) == yyyy;
	}

	public static Date toDate(final int yyyy, final int mm, final int dd) {
		final Calendar cal = Calendar.getInstance();
		cal.set(yyyy, mm - 1, dd);
		return cal.getTime();
	}

	public static final String nowDate() {
		return formatDate(new Date());
	}

	public static final String nowDate(final String format) {
		return formatDate(new Date(), format);
	}

	public static final String nowDateTime() {
		return formatDateTime(new Date());
	}

	public static String formatDate(final Date value) {
		return formatDate(value, DEFAULT_DATE_PATTERN);
	}

	public static String formatDateTime(final Date value) {
		return formatDate(value, DEFAULT_DATETIME_PATTERN);
	}

	/**
	 * ��yyyy-MM-dd HH:mm:ss.SSS��ʽʱ��
	 * 
	 * @param value
	 * @return
	 */
	public static final String formatDateTimeMill(final Date value) {
		return formatDate(value, DEFAULT_DATETIMEMILL_PATTERN);
	}

	public static final Date toDateTimeMill(final String value) {
		return toDate(value, DEFAULT_DATETIMEMILL_PATTERN);
	}

	public static synchronized String formatDate(final Date value, final String pattern) {
		return value == null ? "" : getSdf(pattern).format(value);
	}
	public static synchronized String formatDate(final Date value,int hour, final String pattern) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(value);
		cal.add(Calendar.HOUR_OF_DAY, hour);
		return value == null ? "" : getSdf(pattern).format(cal.getTime());
	}

	public static Date toDate(final String value) {
		return toDate(value, DEFAULT_DATETIME_PATTERN);
	}

	/**
	 * ���������ת����yyyyMMdd��ʽ������
	 * 
	 * @param value
	 * @return ���������ڶ���Ϊ�գ��������׳���ʽ������
	 */
	public static int toNumber(final Date value) {
		return Integer.parseInt(formatDate(value, DEFAULT_DATETONUMBER_PATTERN));
	}

	public static int toNumber(final Date value, final String formate) {
		return Integer.parseInt(formatDate(value, formate));
	}

	public static int toNumber(final String value, final String pattern1, final String pattern2) {
		return Integer.parseInt(formatDate(toDate(value, pattern1), pattern2));
	}

	public static int toNumber(final String value) {
		return toNumber(toDate(value, DEFAULT_DATE_PATTERN));
	}

	public static String getDateFormats(final String date) {
		final Pattern pat = Pattern.compile("[0-9]{1,100}");
		final Matcher mat = pat.matcher(date);
		if(mat.matches()) {
			return "";
		}
		date.trim().replaceAll("  +", " ");
		String dat = "";
		try {
			final String[] dates = date.split(" ");
			String month = dates[0];
			if("Jul".equals(month)) {
				month = "07";
			}
			final String[] times = dates[dates.length - 1].split(":");
			if(times[0].length() == 1) {
				times[0] = "0" + times[0];
			}
			dat = dates[2] + month + dates[1] + times[0] + times[1] + times[2];
		} catch (final Exception e) {
			e.printStackTrace();
		}
		return dat;
	}

	private static final Map<String, SimpleDateFormat> SDFS = new HashMap<String, SimpleDateFormat>(4);
	private static final Lock lockSdf = new ReentrantReadWriteLock().writeLock();

	protected static final SimpleDateFormat getSdf(final String pattern) {
		SimpleDateFormat sdf = SDFS.get(pattern);
		if(null != sdf) return sdf;
		lockSdf.lock();
		try {
			sdf = SDFS.get(pattern);
			if(null == sdf) SDFS.put(pattern, sdf = new SimpleDateFormat(pattern));
		} finally {
			lockSdf.unlock();
		}
		return sdf;
	}

	public static synchronized Date toDate(final String value, final String pattern) {
		try {
			return null == value ? null : getSdf(pattern).parse(value);
		} catch (final ParseException e) {
			return null;
		}
	}

	public static int toDateNum(final Date date, final String pattern) {
		return Integer.valueOf(formatDate(date, pattern));
	}

	public static String formatDateMDH(int time) {
		return DateUtils.formatDate(toDate(String.valueOf(time), "yyyyMMddHH"), "MM-dd HH");
	}

	public static String formatDateMD(int time) {
		return DateUtils.formatDate(toDate(String.valueOf(time), "yyyyMMdd"), "MM-dd");
	}

	public static final String millisecondToDate(final long millis) {
		return millisecondToDate(millis, "");
	}

	public static final String millisecondToDate(final long millis, final String defDate) {
		return millisecondToDate(millis, defDate, DEFAULT_DATETIME_PATTERN);
	}

	public static final String millisecondToDate(final long millis, final String defDate, final String format) {
		try {
			return formatDate(new Date(millis), format);
		} catch (final Exception e) {
			return defDate;
		}
	}

	/**
	 * 0ʱ0��0��
	 */
	public static final String CN_FMT_SEC = "{0,number,integer}��{1,number,integer}��";
	public static final String CN_FMT = "{0,number,integer}ʱ{1,number,integer}��{2,number,integer}��";
	public static final String CN_FMT_MILLS = "{0,number,integer}ʱ{1,number,integer}��{2,number,integer}��{3,number,integer}";
	/**
	 * 0HH0MM0SS
	 */
	public static final String EN_FMT = "{0,number,integer}HH{1,number,integer}MM{2,number,integer}SS";
	public static final String EN_FMT_MILLS = "{0,number,integer}HH{1,number,integer}MM{2,number,integer}SS{3,number,integer}";

	public static final String onLineTimeInfo(final long baseTime) {
		return onLineTimeInfo(baseTime, CN_FMT_MILLS);
	}

	public static final String onLineTimeInfo(final long baseTime, final long nowTime) {
		return onLineTimeInfo(baseTime, nowTime, CN_FMT_MILLS);
	}

	public static final String onLineTimeInfo(final long baseTime, final String showFmt) {
		return onLineTimeInfo(baseTime, System.currentTimeMillis(), showFmt);
	}

	public static final String onLineTimeInfo(final long baseTime, final long nowTime, final String showFmt) {
		final long olTime = nowTime - baseTime;
		final long secs = olTime / 1000;
		final long h = secs / 3600;
		long ma;
		if(h == 0) {
			ma = secs;
		} else
			ma = secs % 3600;
		final long m = ma / 60;
		long sa;
		if(m == 0) sa = ma;
		else
			sa = ma % 60;
		// h+"ʱ"+m+"��"+sa+"��"
		return MessageFormat.format(showFmt, new Object[] { h, m, sa, olTime % 1000 });
	}

	public static final String onLineTimeInfo1(final long time, final String showFmt) {
		final long secs = time / 1000;
		final long h = secs / 3600;
		long ma;
		if(h == 0) {
			ma = secs;
		} else
			ma = secs % 3600;
		final long m = ma / 60;
		long sa;
		if(m == 0) sa = ma;
		else
			sa = ma % 60;
		// h+"ʱ"+m+"��"+sa+"��"
		return MessageFormat.format(showFmt, new Object[] { h, m, sa, time % 1000 });
	}

	public static final Date toZhengDianTime(final Date srcDate) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime();
	}

	public static final Date toMaxDateTimeOfDay(final Date srcDate) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime();
	}

	public static final Date toMinDateTimeOfDay(final Date srcDate) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime();
	}

	public static final Date toMaxDayOfMonth(final Date srcDate) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime();
	}

	public static final Date toMinDayOfMonth(final Date srcDate) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime();
	}

	public static final List<Date> dateToList(final Date start, final Date end) {
		final List<Date> dates = new ArrayList<Date>();
		final Calendar cal = Calendar.getInstance();
		cal.setTime(start);
		while (!cal.getTime().after(end)) {
			dates.add(cal.getTime());
			cal.add(Calendar.HOUR, 1);
		}
		return dates;
	}

	public static final long getSleepTime(final Date date, final String sleepType, int intervalUnits, final int skipFlag) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		intervalUnits += skipFlag;
		if("YEAR".equals(sleepType)) {
			long seconds = 0;
			for (int i = 0; i < intervalUnits; i++) {
				seconds += cal.getActualMaximum(Calendar.DAY_OF_YEAR) * DAY;
				cal.add(Calendar.YEAR, 1);
			}
			return seconds;
		} else if("MONTH".equals(sleepType)) {
			long seconds = 0;
			for (int i = 0; i < intervalUnits; i++) {
				seconds += cal.getActualMaximum(Calendar.DAY_OF_MONTH) * DAY;
				cal.add(Calendar.MONTH, 1);
			}
			return seconds;
		} else if("WEEK".equals(sleepType)) {
			return intervalUnits * WEEK;
		} else if("DATE".equals(sleepType)) {
			return intervalUnits * DAY;
		} else if("HOUR".equals(sleepType)) {
			return intervalUnits * HOUR;
		} else if("MINUTE".equals(sleepType)) {
			return intervalUnits * MINUTE;
		} else if("SECOND".equals(sleepType)) {
			return intervalUnits * SECONDS;
		}
		return Long.MAX_VALUE;
	}

	public static final long getSleepTime(final Date date, final String sleepType, final int intervalUnits) {
		return getSleepTime(date, sleepType, intervalUnits, 1);
	}

	private static final int[] dayArray = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	// ��������
	public static final String[] HOLIDAY = new String[] { "1.1", "5.1", "5.2", "5.3", "10.1", "10.2", "10.3" };
	public static final int STARTHOUR = 8;
	public static final int ENDHOUR = 5;
	private static SimpleDateFormat sdf = new SimpleDateFormat();


	public static List<Date> getDateHours(final Date start, final Date end) {
		final List<Date> dates = new ArrayList<Date>();
		final java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(start);
		while (!cal.getTime().after(end)) {
			dates.add(cal.getTime());
			cal.add(Calendar.HOUR, 1);
		}
		return dates;
	}

	public static List<Date> getDateDays(final Date start, final Date end) {
		final List<Date> dates = new ArrayList<Date>();
		final java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(start);
		while (!cal.getTime().after(end)) {
			dates.add(cal.getTime());
			cal.add(Calendar.DAY_OF_YEAR, 1);
		}
		return dates;
	}

	/**
	 * ȡ���й�ָ�����ڵ������ڵĵ�һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ������ڵĵ�һ��
	 */
	public static java.util.Date getFirstDayOfWeekByCH(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.���date�������գ����0�� 2.���date������һ�����1�� 3.���date�����ڶ������2��
		 * 4.���date�����������3�� 5.���date�������ģ����4�� 6.���date�������壬���5�� 7.���date�����������6��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			gc.add(Calendar.DATE, -6);
			break;
		case Calendar.MONDAY:
			gc.add(Calendar.DATE, 0);
			break;
		case Calendar.TUESDAY:
			gc.add(Calendar.DATE, 1);
			break;
		case Calendar.WEDNESDAY:
			gc.add(Calendar.DATE, -2);
			break;
		case Calendar.THURSDAY:
			gc.add(Calendar.DATE, -3);
			break;
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, -4);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, -5);
			break;
		}
		return gc.getTime();
	}

	/**
	 * �õ�һ�����ִ��׼�ĵ�ǰʱ�����
	 * 
	 * @return
	 */
	public static Calendar getCalendar() {
		return Calendar.getInstance();
	}

	/**
	 * �õ���ǰϵͳʱ���һ���������ַ��ʽ
	 * 
	 * @return String
	 */
	public static String getDateMilliFormat() {
		return getDateMilliFormat(Calendar.getInstance());
	}

	/**
	 * ��һ��Calendar�����ʽ����һ���������ַ������ʽ
	 * 
	 * @param cal
	 * @return String
	 */
	public static String getDateMilliFormat(final java.util.Calendar cal) {
		return getDateFormat(cal, "yyyy-MM-dd HH:mm:ss,SSS");
	}

	/**
	 * ��һ��java.util.Date�����ʽ����һ���������ַ������ʽ
	 * 
	 * @param date
	 * @return String
	 */
	public static String getDateMilliFormat(final java.util.Date date) {
		return getDateFormat(date, "yyyy-MM-dd HH:mm:ss,SSS");
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarMilliFormat(final String strDate) {
		return parseCalendarFormat(strDate, "yyyy-MM-dd HH:mm:ss,SSS");
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateMilliFormat(final String strDate) {
		return parseDateFormat(strDate, "yyyy-MM-dd HH:mm:ss,SSS");
	}

	/**
	 * @return String
	 */
	public static String getDateSecondFormat() {
		return getDateSecondFormat(Calendar.getInstance());
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateSecondFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateSecondFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarSecondFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseCalendarFormat(strDate, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateSecondFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @return String
	 */
	public static String getDateMinuteFormat() {
		final Calendar cal = Calendar.getInstance();
		return getDateMinuteFormat(cal);
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateMinuteFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd HH:mm";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateMinuteFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd HH:mm";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarMinuteFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm";
		return parseCalendarFormat(strDate, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateMinuteFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @return String
	 */
	public static String getDateDayFormat() {
		final Calendar cal = Calendar.getInstance();
		return getDateDayFormat(cal);
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateDayFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateDayFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarDayFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd";
		return parseCalendarFormat(strDate, pattern);
	}

	public static String parseDateStringFormat(final String strDate, final String pattern, final String pattern1) {
		final Date date = parseDateFormat(strDate, pattern);
		return getCurrentDateFormat(date, pattern1);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateDayFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @return String
	 */
	public static String getDateFileFormat() {
		final Calendar cal = Calendar.getInstance();
		return getDateFileFormat(cal);
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateFileFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd_HH-mm-ss";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateFileFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd_HH-mm-ss";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarFileFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd_HH-mm-ss";
		return parseCalendarFormat(strDate, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateFileFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd_HH-mm-ss";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @return String
	 */
	public static String getDateW3CFormat() {
		final Calendar cal = Calendar.getInstance();
		return getDateW3CFormat(cal);
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateW3CFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateW3CFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarW3CFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseCalendarFormat(strDate, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateW3CFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @param cal
	 * @return String
	 */
	public static String getDateFormat(final java.util.Calendar cal) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(cal, pattern);
	}

	/**
	 * @param date
	 * @return String
	 */
	public static String getDateFormat(final java.util.Date date) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return getDateFormat(date, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseCalendarFormat(strDate, pattern);
	}

	/**
	 * @param strDate
	 * @return java.util.Date
	 */
	public static Date parseDateFormat(final String strDate) {
		final String pattern = "yyyy-MM-dd HH:mm:ss";
		return parseDateFormat(strDate, pattern);
	}

	/**
	 * @param cal
	 * @param pattern
	 * @return String
	 */
	public static String getDateFormat(final java.util.Calendar cal, final String pattern) {
		return getDateFormat(cal.getTime(), pattern);
	}

	/**
	 * @param date
	 * @param pattern
	 * @return String
	 */
	public static String getDateFormat(final java.util.Date date, final String pattern) {
		synchronized (sdf) {
			if(null == date) return "";
			String str = null;
			sdf.applyPattern(pattern);
			str = sdf.format(date);
			return str;
		}
	}

	public static String getCurrentDateFormat(java.util.Date date, String pattern) {
		if(date == null) {
			date = new Date();
		}
		if(pattern == null) {
			pattern = DEFAULT_DATE_HH_PATTERN;
		}
		return getDateFormat(date, pattern);
	}

	/**
	 * ������WEB����ʾʱ��ʱ��ʹ�ô˷���,���Ҫ���ص�ֵΪ��,���ս�����һ��WEB�ϵı�׼�ո�,
	 * ��˿��Խ����ʱ��ʱ�����Ϊ��ʱҳ������ʾnull���������
	 * 
	 * @param date
	 * @param pattern
	 * @return
	 */
	public static String getDateFormatByWEB(final Date date, final String pattern) {
		final String returnValue = getDateFormat(date, pattern);
		if(null == returnValue || "".equals("returnValue")) return "&nbsp;";
		return returnValue;
	}

	/**
	 * ��ݴ����ʱ��õ�һ��"����"��ʽ���ַ�,��������null,�Ե�ǰʱ��Ϊ׼.
	 * 
	 * @param date
	 * @return һ��"����"��ʽ���ַ�,��"200801"��ʾΪ2008��1��
	 */
	public static String getYearMonth(Date date) {
		if(null == date) date = new Date();
		return getDateFormat(date, "yyyyMM");
	}

	/**
	 * @param strDate
	 * @param pattern
	 * @return java.util.Calendar
	 */
	public static Calendar parseCalendarFormat(final String strDate, final String pattern) {
		synchronized (sdf) {
			Calendar cal = null;
			sdf.applyPattern(pattern);
			try {
				sdf.parse(strDate);
				cal = sdf.getCalendar();
			} catch (final Exception e) {}
			return cal;
		}
	}

	/**
	 * @param strDate
	 * @param pattern
	 * @return java.util.Date
	 */
	public static Date parseDateFormat(final String strDate, final String pattern) {
		synchronized (sdf) {
			Date date = null;
			sdf.applyPattern(pattern);
			try {
				date = sdf.parse(strDate);
			} catch (final Exception e) {}
			return date;
		}
	}

	public static int getLastDayOfMonth(final int month) {
		if(month < 1 || month > 12) {
			return -1;
		}
		int retn = 0;
		if(month == 2) {
			if(isLeapYear()) {
				retn = 29;
			} else {
				retn = dayArray[month - 1];
			}
		} else {
			retn = dayArray[month - 1];
		}
		return retn;
	}

	public static int getLastDayOfMonth(final int year, final int month) {
		if(month < 1 || month > 12) {
			return -1;
		}
		int retn = 0;
		if(month == 2) {
			if(isLeapYear(year)) {
				retn = 29;
			} else {
				retn = dayArray[month - 1];
			}
		} else {
			retn = dayArray[month - 1];
		}
		return retn;
	}

	public static boolean isLeapYear() {
		final Calendar cal = Calendar.getInstance();
		final int year = cal.get(Calendar.YEAR);
		return isLeapYear(year);
	}

	public static boolean isLeapYear(final int year) {
		/**
		 * ��ϸ��ƣ� 1.��400��������꣬���� 2.���ܱ�4����������� 3.�ܱ�4���ͬʱ���ܱ�100�����������
		 * 3.�ܱ�4���ͬʱ�ܱ�100�����������
		 */
		if(year % 400 == 0) return true;
		else if(year % 4 == 0) {
			if(year % 100 == 0) return false;
			return true;
		} else
			return false;
	}

	/**
	 * �ж�ָ�����ڵ�����Ƿ�������
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return �Ƿ�����
	 */
	public static boolean isLeapYear(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.��400��������꣬���� 2.���ܱ�4����������� 3.�ܱ�4���ͬʱ���ܱ�100�����������
		 * 3.�ܱ�4���ͬʱ�ܱ�100�����������
		 */
		// int year = date.getYear();
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		final int year = gc.get(Calendar.YEAR);
		return isLeapYear(year);
	}

	public static boolean isLeapYear(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.��400��������꣬���� 2.���ܱ�4����������� 3.�ܱ�4���ͬʱ���ܱ�100�����������
		 * 3.�ܱ�4���ͬʱ�ܱ�100�����������
		 */
		final int year = gc.get(Calendar.YEAR);
		return isLeapYear(year);
	}

	/**
	 * �õ�ָ�����ڵ�ǰһ��������
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ�ǰһ��������
	 */
	public static java.util.Date getPreviousWeekDay(final java.util.Date date) {
		{
			/**
			 * ��ϸ��ƣ� 1.���date�������գ����3�� 2.���date�����������2�� 3.�����1��
			 */
			final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
			gc.setTime(date);
			return getPreviousWeekDay(gc);
			// switch ( gc.get( Calendar.DAY_OF_WEEK ) )
			// {
			// case ( Calendar.MONDAY ):
			// gc.add( Calendar.DATE, -3 );
			// break;
			// case ( Calendar.SUNDAY ):
			// gc.add( Calendar.DATE, -2 );
			// break;
			// default:
			// gc.add( Calendar.DATE, -1 );
			// break;
			// }
			// return gc.getTime();
		}
	}

	public static java.util.Date getPreviousWeekDay(final java.util.Calendar gc) {
		{
			/**
			 * ��ϸ��ƣ� 1.���date�������գ����3�� 2.���date�����������2�� 3.�����1��
			 */
			switch (gc.get(Calendar.DAY_OF_WEEK)) {
			case Calendar.MONDAY:
				gc.add(Calendar.DATE, -3);
				break;
			case Calendar.SUNDAY:
				gc.add(Calendar.DATE, -2);
				break;
			default:
				gc.add(Calendar.DATE, -1);
				break;
			}
			return gc.getTime();
		}
	}

	/**
	 * �õ�ָ�����ڵĺ�һ��������
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵĺ�һ��������
	 */
	public static java.util.Date getNextWeekDay(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.���date�������壬���3�� 2.���date�����������2�� 3.�����1��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, 3);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, 2);
			break;
		default:
			gc.add(Calendar.DATE, 1);
			break;
		}
		return gc.getTime();
	}

	public static java.util.Calendar getNextWeekDay(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.���date�������壬���3�� 2.���date�����������2�� 3.�����1��
		 */
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, 3);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, 2);
			break;
		default:
			gc.add(Calendar.DATE, 1);
			break;
		}
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ���һ���µ����һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ���µ����һ��
	 */
	public static java.util.Date getLastDayOfNextMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.����getNextMonth���õ�ǰʱ�� 2.��1Ϊ������getLastDayOfMonth
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.setTime(getNextMonth(gc.getTime()));
		gc.setTime(getLastDayOfMonth(gc.getTime()));
		return gc.getTime();
	}

	/**
	 * ȡ��ָ�����ڵ���һ�����ڵ����һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ�����ڵ����һ��
	 */
	public static java.util.Date getLastDayOfNextWeek(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.����getNextWeek���õ�ǰʱ�� 2.��1Ϊ������getLastDayOfWeek
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.setTime(getNextWeek(gc.getTime()));
		gc.setTime(getLastDayOfWeek(gc.getTime()));
		return gc.getTime();
	}

	/**
	 * ȡ��ָ�����ڵ���һ���µĵ�һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ���µĵ�һ��
	 */
	public static java.util.Date getFirstDayOfNextMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.����getNextMonth���õ�ǰʱ�� 2.��1Ϊ������getFirstDayOfMonth
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.setTime(getNextMonth(gc.getTime()));
		gc.setTime(getFirstDayOfMonth(gc.getTime()));
		return gc.getTime();
	}

	public static java.util.Calendar getFirstDayOfNextMonth(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.����getNextMonth���õ�ǰʱ�� 2.��1Ϊ������getFirstDayOfMonth
		 */
		gc.setTime(getNextMonth(gc.getTime()));
		gc.setTime(getFirstDayOfMonth(gc.getTime()));
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ���һ�����ڵĵ�һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ�����ڵĵ�һ��
	 */
	public static java.util.Date getFirstDayOfNextWeek(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.����getNextWeek���õ�ǰʱ�� 2.��1Ϊ������getFirstDayOfWeek
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.setTime(getNextWeek(gc.getTime()));
		gc.setTime(getFirstDayOfWeek(gc.getTime()));
		return gc.getTime();
	}

	public static java.util.Calendar getFirstDayOfNextWeek(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.����getNextWeek���õ�ǰʱ�� 2.��1Ϊ������getFirstDayOfWeek
		 */
		gc.setTime(getNextWeek(gc.getTime()));
		gc.setTime(getFirstDayOfWeek(gc.getTime()));
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ���һ����
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ����
	 */
	public static java.util.Date getNextMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڵ��·ݼ�1
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.add(Calendar.MONTH, 1);
		return gc.getTime();
	}

	/**
	 * ȡ��ָ�����ڵ���һ����
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ����
	 */
	public static java.util.Date getPreviewMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڵ��·ݼ�1
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.add(Calendar.MONTH, -1);
		return gc.getTime();
	}

	public static String getPreviewMonth(final String date) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڵ��·ݼ�1
		 */
		String dateBefore = null;
		if("01".endsWith(date.substring(6, 7))) {
			dateBefore = Integer.parseInt(date.substring(0, 4)) - 1 + "-12";
		} else {
			final int m = Integer.parseInt(date.substring(5, 7)) - 1;
			if(m < 10) {
				dateBefore = date.substring(0, 4) + "-0" + m;
			} else {
				dateBefore = date.substring(0, 4) + "-" + m;
			}
		}
		return dateBefore;
	}

	public static java.util.Calendar getNextMonth(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڵ��·ݼ�1
		 */
		gc.add(Calendar.MONTH, 1);
		return gc;
	}

	/**
	 * ��ȡ��ʱ�����һ��Сʱ��
	 * 
	 * @param curDate
	 * @return
	 */
	public static final Date getPreviousHour(final Date curDate) {
		if(null == curDate) return curDate;
		final Calendar cal = Calendar.getInstance();
		cal.setTime(curDate);
		cal.add(Calendar.HOUR_OF_DAY, -1);
		return cal.getTime();
	}

	/**
	 * ��ȡ��ʱ�����һ��Сʱ��
	 * 
	 * @param curDate
	 * @return
	 */
	public static final Date getNextHour(final Date curDate) {
		if(null == curDate) return curDate;
		final Calendar cal = Calendar.getInstance();
		cal.setTime(curDate);
		cal.add(Calendar.HOUR_OF_DAY, 1);
		return cal.getTime();
	}

	/**
	 * ȡ��ָ�����ڵ���һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ��
	 */
	public static java.util.Date getNextDay(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڼ�1��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.add(Calendar.DATE, 1);
		return gc.getTime();
	}

	public static java.util.Calendar getNextDay(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڼ�1��
		 */
		gc.add(Calendar.DATE, 1);
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ���һ������
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ���һ������
	 */
	public static java.util.Date getNextWeek(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڼ�7��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.add(Calendar.DATE, 7);
		return gc.getTime();
	}

	public static Date getPreviousWeek(final Date date) {
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.add(Calendar.DATE, -7);
		return gc.getTime();
	}

	public static java.util.Calendar getNextWeek(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.ָ�����ڼ�7��
		 */
		gc.add(Calendar.DATE, 7);
		return gc;
	}

	public static Calendar getPreviousWeek(final Calendar gc) {
		gc.add(Calendar.DATE, -7);
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ������ڵ����һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ������ڵ����һ��
	 */
	public static java.util.Date getLastDayOfWeek(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.���date�������գ����6�� 2.���date������һ�����5�� 3.���date�����ڶ������4��
		 * 4.���date�����������3�� 5.���date�������ģ����2�� 6.���date�������壬���1�� 7.���date�����������0��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			gc.add(Calendar.DATE, 6);
			break;
		case Calendar.MONDAY:
			gc.add(Calendar.DATE, 5);
			break;
		case Calendar.TUESDAY:
			gc.add(Calendar.DATE, 4);
			break;
		case Calendar.WEDNESDAY:
			gc.add(Calendar.DATE, 3);
			break;
		case Calendar.THURSDAY:
			gc.add(Calendar.DATE, 2);
			break;
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, 1);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, 0);
			break;
		}
		return gc.getTime();
	}

	/**
	 * ȡ��ָ�����ڵ������ڵĵ�һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ������ڵĵ�һ��
	 */
	public static java.util.Date getFirstDayOfWeek(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.���date�������գ����0�� 2.���date������һ�����1�� 3.���date�����ڶ������2��
		 * 4.���date�����������3�� 5.���date�������ģ����4�� 6.���date�������壬���5�� 7.���date�����������6��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			gc.add(Calendar.DATE, 0);
			break;
		case Calendar.MONDAY:
			gc.add(Calendar.DATE, -1);
			break;
		case Calendar.TUESDAY:
			gc.add(Calendar.DATE, -2);
			break;
		case Calendar.WEDNESDAY:
			gc.add(Calendar.DATE, -3);
			break;
		case Calendar.THURSDAY:
			gc.add(Calendar.DATE, -4);
			break;
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, -5);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, -6);
			break;
		}
		return gc.getTime();
	}

	public static java.util.Calendar getFirstDayOfWeek(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.���date�������գ����0�� 2.���date������һ�����1�� 3.���date�����ڶ������2��
		 * 4.���date�����������3�� 5.���date�������ģ����4�� 6.���date�������壬���5�� 7.���date�����������6��
		 */
		switch (gc.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			gc.add(Calendar.DATE, 0);
			break;
		case Calendar.MONDAY:
			gc.add(Calendar.DATE, -1);
			break;
		case Calendar.TUESDAY:
			gc.add(Calendar.DATE, -2);
			break;
		case Calendar.WEDNESDAY:
			gc.add(Calendar.DATE, -3);
			break;
		case Calendar.THURSDAY:
			gc.add(Calendar.DATE, -4);
			break;
		case Calendar.FRIDAY:
			gc.add(Calendar.DATE, -5);
			break;
		case Calendar.SATURDAY:
			gc.add(Calendar.DATE, -6);
			break;
		}
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ����·ݵ����һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ����·ݵ����һ��
	 */
	public static java.util.Date getLastDayOfMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.���date��1�£���Ϊ31�� 2.���date��2�£���Ϊ28�� 3.���date��3�£���Ϊ31��
		 * 4.���date��4�£���Ϊ30�� 5.���date��5�£���Ϊ31�� 6.���date��6�£���Ϊ30�� 7.���date��7�£���Ϊ31��
		 * 8.���date��8�£���Ϊ31�� 9.���date��9�£���Ϊ30�� 10.���date��10�£���Ϊ31��
		 * 11.���date��11�£���Ϊ30�� 12.���date��12�£���Ϊ31�� 1.���date�������2�£���Ϊ29��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		switch (gc.get(Calendar.MONTH)) {
		case 0:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 1:
			gc.set(Calendar.DAY_OF_MONTH, 28);
			break;
		case 2:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 3:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 4:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 5:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 6:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 7:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 8:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 9:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 10:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 11:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		}
		// �������
		if(gc.get(Calendar.MONTH) == Calendar.FEBRUARY && isLeapYear(gc.get(Calendar.YEAR))) {
			gc.set(Calendar.DAY_OF_MONTH, 29);
		}
		return gc.getTime();
	}

	public static java.util.Calendar getLastDayOfMonth(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.���date��1�£���Ϊ31�� 2.���date��2�£���Ϊ28�� 3.���date��3�£���Ϊ31��
		 * 4.���date��4�£���Ϊ30�� 5.���date��5�£���Ϊ31�� 6.���date��6�£���Ϊ30�� 7.���date��7�£���Ϊ31��
		 * 8.���date��8�£���Ϊ31�� 9.���date��9�£���Ϊ30�� 10.���date��10�£���Ϊ31��
		 * 11.���date��11�£���Ϊ30�� 12.���date��12�£���Ϊ31�� 1.���date�������2�£���Ϊ29��
		 */
		switch (gc.get(Calendar.MONTH)) {
		case 0:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 1:
			gc.set(Calendar.DAY_OF_MONTH, 28);
			break;
		case 2:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 3:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 4:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 5:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 6:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 7:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 8:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 9:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		case 10:
			gc.set(Calendar.DAY_OF_MONTH, 30);
			break;
		case 11:
			gc.set(Calendar.DAY_OF_MONTH, 31);
			break;
		}
		// �������
		if(gc.get(Calendar.MONTH) == Calendar.FEBRUARY && isLeapYear(gc.get(Calendar.YEAR))) {
			gc.set(Calendar.DAY_OF_MONTH, 29);
		}
		return gc;
	}

	/**
	 * ȡ��ָ�����ڵ����·ݵĵ�һ��
	 * 
	 * @param date
	 *          ָ�����ڡ�
	 * @return ָ�����ڵ����·ݵĵ�һ��
	 */
	public static java.util.Date getFirstDayOfMonth(final java.util.Date date) {
		/**
		 * ��ϸ��ƣ� 1.����Ϊ1��
		 */
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		gc.set(Calendar.DAY_OF_MONTH, 1);
		return gc.getTime();
	}

	public static java.util.Calendar getFirstDayOfMonth(final java.util.Calendar gc) {
		/**
		 * ��ϸ��ƣ� 1.����Ϊ1��
		 */
		gc.set(Calendar.DAY_OF_MONTH, 1);
		return gc;
	}

	/**
	 * �����ڶ���ת����Ϊָ��ORA���ڡ�ʱ���ʽ���ַ���ʽ��������ڶ���Ϊ�գ����� һ�����ַ���󣬶���һ���ն���
	 * 
	 * @param theDate
	 *          ��Ҫת��Ϊ�ַ�����ڶ���
	 * @param hasTime
	 *          ���ص��ַ��ʱ����Ϊtrue
	 * @return ת���Ľ��
	 */
	public static String toOraString(final Date theDate, final boolean hasTime) {
		/**
		 * ��ϸ��ƣ� 1.�����ʱ�䣬�����ø�ʽΪgetOraDateTimeFormat()�ķ���ֵ
		 * 2.�������ø�ʽΪgetOraDateFormat()�ķ���ֵ 3.����toString(Date theDate, DateFormat
		 * theDateFormat)
		 */
		DateFormat theFormat;
		if(hasTime) {
			theFormat = getOraDateTimeFormat();
		} else {
			theFormat = getOraDateFormat();
		}
		return toString(theDate, theFormat);
	}

	/**
	 * �����ڶ���ת����Ϊָ�����ڡ�ʱ���ʽ���ַ���ʽ��������ڶ���Ϊ�գ����� һ�����ַ���󣬶���һ���ն���
	 * 
	 * @param theDate
	 *          ��Ҫת��Ϊ�ַ�����ڶ���
	 * @param hasTime
	 *          ���ص��ַ��ʱ����Ϊtrue
	 * @return ת���Ľ��
	 */
	public static String toString(final Date theDate, final boolean hasTime) {
		/**
		 * ��ϸ��ƣ� 1.�����ʱ�䣬�����ø�ʽΪgetDateTimeFormat�ķ���ֵ 2.�������ø�ʽΪgetDateFormat�ķ���ֵ
		 * 3.����toString(Date theDate, DateFormat theDateFormat)
		 */
		DateFormat theFormat;
		if(hasTime) {
			theFormat = getDateTimeFormat();
		} else {
			theFormat = getDateFormat();
		}
		return toString(theDate, theFormat);
	}

	/**
	 * ��׼���ڸ�ʽ
	 */
	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy");
	/**
	 * ��׼ʱ���ʽ
	 */
	private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("MM/dd/yyyy HH:mm");
	/**
	 * ��ʱ����ı�׼ʱ���ʽ
	 */
	// private static final SimpleDateFormat DATE_TIME_EXTENDED_FORMAT = new
	// SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
	/**
	 * ORA��׼���ڸ�ʽ
	 */
	private static final SimpleDateFormat ORA_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
	/**
	 * ORA��׼ʱ���ʽ
	 */
	private static final SimpleDateFormat ORA_DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");

	/**
	 * ��ʱ�����ORA��׼ʱ���ʽ
	 */
	// private static final SimpleDateFormat ORA_DATE_TIME_EXTENDED_FORMAT = new
	// SimpleDateFormat("yyyyMMddHHmmss");
	/**
	 * ����һ����׼���ڸ�ʽ�Ŀ�¡
	 * 
	 * @return ��׼���ڸ�ʽ�Ŀ�¡
	 */
	public static DateFormat getDateFormat() {
		/**
		 * ��ϸ��ƣ� 1.����DATE_FORMAT
		 */
		final SimpleDateFormat theDateFormat = (SimpleDateFormat) DATE_FORMAT.clone();
		theDateFormat.setLenient(false);
		return theDateFormat;
	}

	/**
	 * ����һ����׼ʱ���ʽ�Ŀ�¡
	 * 
	 * @return ��׼ʱ���ʽ�Ŀ�¡
	 */
	public static DateFormat getDateTimeFormat() {
		/**
		 * ��ϸ��ƣ� 1.����DATE_TIME_FORMAT
		 */
		final SimpleDateFormat theDateTimeFormat = (SimpleDateFormat) DATE_TIME_FORMAT.clone();
		theDateTimeFormat.setLenient(false);
		return theDateTimeFormat;
	}

	/**
	 * ����һ����׼ORA���ڸ�ʽ�Ŀ�¡
	 * 
	 * @return ��׼ORA���ڸ�ʽ�Ŀ�¡
	 */
	public static DateFormat getOraDateFormat() {
		/**
		 * ��ϸ��ƣ� 1.����ORA_DATE_FORMAT
		 */
		final SimpleDateFormat theDateFormat = (SimpleDateFormat) ORA_DATE_FORMAT.clone();
		theDateFormat.setLenient(false);
		return theDateFormat;
	}

	/**
	 * ����һ����׼ORAʱ���ʽ�Ŀ�¡
	 * 
	 * @return ��׼ORAʱ���ʽ�Ŀ�¡
	 */
	public static DateFormat getOraDateTimeFormat() {
		/**
		 * ��ϸ��ƣ� 1.����ORA_DATE_TIME_FORMAT
		 */
		final SimpleDateFormat theDateTimeFormat = (SimpleDateFormat) ORA_DATE_TIME_FORMAT.clone();
		theDateTimeFormat.setLenient(false);
		return theDateTimeFormat;
	}

	/**
	 * ��һ�����ڶ���ת����Ϊָ�����ڡ�ʱ���ʽ���ַ� ������ڶ���Ϊ�գ�����һ�����ַ�����һ���ն���
	 * 
	 * @param theDate
	 *          Ҫת�������ڶ���
	 * @param theDateFormat
	 *          ���ص������ַ�ĸ�ʽ
	 * @return ת�����
	 */
	public static String toString(final Date theDate, final DateFormat theDateFormat) {
		/**
		 * ��ϸ��ƣ� 1.theDateΪ�գ��򷵻�"" 2.����ʹ��theDateFormat��ʽ��
		 */
		if(theDate == null) return "";
		return theDateFormat.format(theDate);
	}

	/**
	 * �õ�����
	 * 
	 * @param y
	 *          String
	 * @param m
	 *          String
	 * @param d
	 *          String
	 * @return Date
	 */
	public static Date getDate(final String y, final String m, final String d) {
		return getDate(Integer.parseInt(y), Integer.parseInt(m), Integer.parseInt(d));
	}

	public static Date getDate(final int y, final int m, final int d) {
		final java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.set(Calendar.YEAR, y);
		cal.set(Calendar.MONTH, m - 1);
		cal.set(Calendar.DAY_OF_MONTH, d);
		return cal.getTime();
	}

	public static Date gotoLastSecond(final Date date) {
		final java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime();
	}

	public static Date gotoFirstSecond(final Date date) {
		final java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 1);
		return cal.getTime();
	}

	public static final int UNIT_DAY = 0;
	public static final int UNIT_WEEK = 1;
	public static final int UNIT_MONTH = 2;
	public static final int UNIT_YEAR = 3;

	public static String getYyyymmdd(final Date date, final int count, final int type) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		if(type == UNIT_DAY) {
			cal.add(Calendar.DATE, count);
		} else if(type == UNIT_WEEK) {
			cal.add(Calendar.WEEK_OF_YEAR, count);
		} else if(type == UNIT_MONTH) {
			cal.add(Calendar.MONTH, count);
		} else if(type == UNIT_YEAR) {
			cal.add(Calendar.YEAR, count);
		}
		final int y = cal.get(Calendar.YEAR);
		final int m = cal.get(Calendar.MONTH) + 1;
		final int d = cal.get(Calendar.DAY_OF_MONTH);
		return y + twoDigits(m) + twoDigits(d);
	}

	public static String twoDigits(final int day) // Ϊ�������������ܹ����룬����1-9 ǰ����0
	{
		final String stringDay = String.valueOf(day); // ȡ��day��ֵ
		if(stringDay.length() == 1) // ����ַ���Ϊ1
		return "0" + stringDay; // �����ַ�ǰ����
		return stringDay;
	}

	public static String getChinaNumber(final int num) {
		String ConvNumber = "";
		switch (num) {
		case 0:
			ConvNumber = "��";
			break;
		case 1:
			ConvNumber = "һ";
			break;
		case 2:
			ConvNumber = "��";
			break;
		case 3:
			ConvNumber = "��";
			break;
		case 4:
			ConvNumber = "��";
			break;
		case 5:
			ConvNumber = "��";
			break;
		case 6:
			ConvNumber = "��";
			break;
		case 7:
			ConvNumber = "��";
			break;
		case 8:
			ConvNumber = "��";
			break;
		case 9:
			ConvNumber = "��";
			break;
		case 10:
			ConvNumber = "ʮ";
			break;
		case 11:
			ConvNumber = "ʮһ";
			break;
		case 12:
			ConvNumber = "ʮ��";
			break;
		case 13:
			ConvNumber = "ʮ��";
			break;
		case 14:
			ConvNumber = "ʮ��";
			break;
		case 15:
			ConvNumber = "ʮ��";
			break;
		case 16:
			ConvNumber = "ʮ��";
			break;
		case 17:
			ConvNumber = "ʮ��";
			break;
		case 18:
			ConvNumber = "ʮ��";
			break;
		case 19:
			ConvNumber = "ʮ��";
			break;
		case 20:
			ConvNumber = "��ʮ";
			break;
		case 21:
			ConvNumber = "��ʮһ";
			break;
		case 22:
			ConvNumber = "��ʮ��";
			break;
		case 23:
			ConvNumber = "��ʮ��";
			break;
		case 24:
			ConvNumber = "��ʮ��";
			break;
		case 25:
			ConvNumber = "��ʮ��";
			break;
		case 26:
			ConvNumber = "��ʮ��";
			break;
		case 27:
			ConvNumber = "��ʮ��";
			break;
		case 28:
			ConvNumber = "��ʮ��";
			break;
		case 29:
			ConvNumber = "��ʮ��";
			break;
		case 30:
			ConvNumber = "��ʮ";
			break;
		case 31:
			ConvNumber = "��ʮһ";
			break;
		}
		return ConvNumber;
	}

	/**
	 * ��ȡ���ĸ�ʽ�������ַ�
	 * 
	 * @param date
	 *          Date
	 * @return String
	 */
	public static String getChinaDataFormat(final Date date) {
		try {
			final Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			final String y = Integer.toString(cal.get(Calendar.YEAR));
			final String m = Integer.toString(cal.get(Calendar.MONTH));
			final String d = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
			String result = "";
			for (int i = 0; i < y.length(); i++) {
				final int a = Integer.parseInt(y.substring(i, i + 1));
				result += getChinaNumber(a);
			}
			result += "��";
			result += getChinaNumber(Integer.parseInt(m) + 1) + "��";
			result += getChinaNumber(Integer.parseInt(d)) + "��";
			return result;
		} catch (final Exception e) {
			return "";
		}
	}

	/*
	 * ����ǰ���ڼӼ�n���� �紫���ַ���"-5" ��Ϊ����ǰ���ڼ�ȥ5������� �紫���ַ���"5" ��Ϊ����ǰ���ڼ���5�������� �����ִ�
	 * ��(1999-02-03)
	 */
	public static String dateAdd(final String to) {
		// ���ڴ���ģ�� (�����ڼ���ĳЩ����ȥ����)�����ַ�
		int strTo;
		try {
			strTo = Integer.parseInt(to);
		} catch (final Exception e) {
			System.out.println("���ڱ�ʶת������! : \n:::" + to + "����תΪ������");
			e.printStackTrace();
			strTo = 0;
		}
		final Calendar strDate = Calendar.getInstance(); // java.util��
		strDate.add(Calendar.DATE, strTo); // ���ڼ� ������Ὣ�±䶯
		// ��� (��-��-��) �ַ�
		final String meStrDate = strDate.get(Calendar.YEAR) + "-" + String.valueOf(strDate.get(Calendar.MONTH) + 1) + "-" + strDate.get(Calendar.DATE);
		return meStrDate;
	}

	/*
	 * ������date�Ӽ�n���� �紫���ַ���"-5" ��Ϊ����ǰ���ڼ�ȥ5������� �紫���ַ���"5" ��Ϊ����ǰ���ڼ���5�������� ����DATE
	 */
	public static Date dateAdd(final Date date, final String n) {
		// ���ڴ���ģ�� (�����ڼ���ĳЩ����ȥ����)�����ַ�
		int strTo;
		try {
			strTo = Integer.parseInt(n);
		} catch (final Exception e) {
			System.out.println("���ڱ�ʶת������! : \n:::" + n + "����תΪ������");
			e.printStackTrace();
			strTo = 0;
		}
		final Calendar strDate = Calendar.getInstance(); // java.util��
		strDate.setTime(date);
		strDate.add(Calendar.DATE, strTo); // ���ڼ� ������Ὣ�±䶯
		return strDate.getTime();
	}

	/**
	 * ���ص�ǰ�����ǵڼ���
	 * 
	 * @param date
	 *          Date
	 * @return int
	 */
	public static int getCurrentWeek(final Date date) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.WEEK_OF_YEAR);
	}

	public static int getCurrentWeekOnMonth(final Date date) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.WEEK_OF_MONTH);
	}

	/**
	 * ��ȡĳһ�������
	 * 
	 * @param y
	 *          int
	 * @return int
	 */
	public static int getWeekCountOfYear(final int y) {
		final Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, y);
		return cal.getMaximum(Calendar.WEEK_OF_YEAR);
	}

	/**
	 * ��ȡĳ��ĳһ�ܵĵ�һ��
	 * 
	 * @param weekno
	 *          int
	 * @return Date
	 */
	public static Date getFirstDayDateOfWeekNo(final int y, final int weekno) {
		final Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, y);
		cal.set(Calendar.WEEK_OF_YEAR, weekno);
		return getFirstDayOfWeek(cal.getTime());
	}

	public static Date[] getStartAndEndDateOfDay(final Date date) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		final Date[] result = new Date[2];
		cal.set(Calendar.HOUR, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		result[0] = cal.getTime();
		cal.set(Calendar.HOUR, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		result[1] = cal.getTime();
		return result;
	}

	public static Date[] getStartAndEndDateOfWeek(final Date date) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		final Date[] result = new Date[2];
		final int firstDay = cal.getMinimum(Calendar.DAY_OF_WEEK);
		final int lastDay = cal.getMaximum(Calendar.DAY_OF_WEEK);
		cal.set(Calendar.DAY_OF_WEEK, firstDay);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		result[0] = cal.getTime();
		cal.set(Calendar.DAY_OF_WEEK, lastDay);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		result[1] = cal.getTime();
		return result;
	}

	public static Date[] getStartAndEndDateOfMonth(final Date date) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		final Date[] result = new Date[2];
		final int firstDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
		final int lastDay = cal.getMaximum(Calendar.DAY_OF_MONTH);
		cal.set(Calendar.DAY_OF_MONTH, firstDay);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		result[0] = cal.getTime();
		cal.set(Calendar.DAY_OF_MONTH, lastDay);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		result[1] = cal.getTime();
		return result;
	}

	/**
	 * ��ȡһ��ʱ����ڵ����б�,
	 * 
	 * @author Fei
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static List<Integer> getYearList(final Date startTime, final Date endTime) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(startTime);
		final int syear = cal.get(Calendar.YEAR);// start year
		cal.setTime(endTime);
		final int eyear = cal.get(Calendar.YEAR);// end year
		final List<Integer> yearList = new ArrayList<Integer>();
		for (int year = syear; year < eyear + 1; year++) {
			yearList.add(year);
		}
		return yearList;
	}

	/**
	 * ��ȡ��ǰʱ����������
	 * 
	 * @param date
	 * @return
	 */
	public static String getYear(Date date) {
		if(null == date) date = new Date();
		return getDateFormat(date, "yyyy");
	}

	/**
	 * ������������������
	 * 
	 * @param startDate
	 *          ��ʼʱ��
	 * @param endDate
	 *          ����ʱ��
	 * @return
	 */
	public static int getDifferDate(final String startDate, final String endDate) {
		final Date start = parseDateFormat(startDate, "yyyy-MM-dd");
		final Date end = parseDateFormat(endDate, "yyyy-MM-dd");
		return getDifferDate(start, end);
	}

	public static int getDifferDate(final Date startDate, final Date endDate) {
		// return getDifferDate(getDateFormat(startDate, "yyyy-MM-dd"),
		// getDateFormat(endDate, "yyyy-MM-dd"));
		final long startTime = startDate.getTime();
		final long endTime = endDate.getTime();
		return Math.abs((int) ((endTime - startTime) / DateUtils.DAY));
	}

	public static List<String> getDifferPrefix(final String startDate, final String endDate) {
		return getDifferPrefix(startDate, endDate, "yyMMdd");
	}

	/**
	 * ��ȡ����ָ������֮��������б�
	 * 
	 * @param startDate
	 * @param endDate
	 * @param pattern
	 * @return
	 */
	public static List<String> getDifferPrefix(final String startDate, final String endDate, final String pattern) {
		final List<String> tablePrefix = new ArrayList<String>();
		final Date start = parseDateFormat(startDate, "yyyy-MM-dd");
		final Date end = parseDateFormat(endDate, "yyyy-MM-dd");
		final GregorianCalendar startCalendar = new GregorianCalendar();
		final GregorianCalendar endCalendar = new GregorianCalendar();
		startCalendar.setTime(start);
		endCalendar.setTime(end);
		while (startCalendar.before(endCalendar)) {
			tablePrefix.add(getDateFormat(startCalendar, pattern));
			startCalendar.add(Calendar.DATE, 1);
		}
		tablePrefix.add(getDateFormat(endCalendar, pattern));
		return tablePrefix;
	}

	public static String getShortYearDate(final String date) {
		final Date start = parseDateFormat(date, "yyyy-MM-dd");
		return getDateFormat(start, "yyMMdd");
	}

	public static String getLongYearDate(final String date) {
		final Date start = parseDateFormat(date, "yyyy-MM-dd");
		return getDateFormat(start, "yyyyMMdd");
	}

	public static String[] getDateFormat(final String date) {
		return getDateFormat(date, "yyyy-MM-dd HH");
	}

	public static String[] getDateFormat(final String date, final String pattern) {
		final String[] obj = new String[4];
		final Date start = parseDateFormat(date, pattern);
		obj[0] = getDateFormat(start, "yyyyMMdd");
		obj[1] = getDateFormat(start, "yyMMdd");
		obj[2] = getDateFormat(start, "HH");
		obj[3] = getDateFormat(start, "yyyy-MM-dd");
		return obj;
	}

	/**
	 * ��õ�ǰ����ǰ������n��Ĺ�����
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static List<String> getSeriesWorkDay(final String dateStr, final int n, final String pattern) {
		final List<String> list = new ArrayList<String>();
		Date currDate = parseDateFormat(dateStr, "yyyy-MM-dd");
		list.add(getDateFormat(currDate, pattern));
		Date seriesDate = null;
		for (int i = 1; i < n; i++) {
			seriesDate = getPreviousWeekDay(currDate);
			list.add(getDateFormat(seriesDate, pattern));
			currDate = seriesDate;
		}
		return list;
	}

	public static int[] getSeriesWorkDay(Date startDate, final int nDays) {
		final int[] seriesDays = new int[nDays];
		for (int i = 0; i < nDays; i++) {
			seriesDays[i] = Integer.parseInt(getDateFormat(startDate, "yyyyMMdd"));
			startDate = getPreviousWeekDay(startDate);
		}
		return seriesDays;
	}

	/**
	 * ��ÿ�ʼʱ��ͽ���ʱ��֮��Ĺ�����
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static List<String> getSeriesWorkDayWeek(final String dateStart, final String dateEnd) {
		final List<String> list = new ArrayList<String>();
		Date currDate = parseDateFormat(dateEnd, "yyyy-MM-dd");
		final Date strDate = parseDateFormat(dateStart, "yyyy-MM-dd");
		list.add(getDateFormat(currDate, "yyyy-MM-dd"));
		Date seriesDate = null;
		while (currDate.after(strDate)) {
			seriesDate = getPreviousWeekDay(currDate);
			if(!seriesDate.before(strDate)) {
				list.add(getDateFormat(seriesDate, "yyyy-MM-dd"));
			}
			currDate = seriesDate;
		}
		return list;
	}

	/**
	 * ��ÿ�ʼʱ��ͽ���ʱ��֮��������б�
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static List<String> getSeriesDay(final String dateStart, final String dateEnd) {
		final List<String> list = new ArrayList<String>();
		Date currDate = parseDateFormat(dateEnd, "yyyy-MM-dd");
		final Date strDate = parseDateFormat(dateStart, "yyyy-MM-dd");
		list.add(getDateFormat(currDate, "yyyy-MM-dd"));
		Date seriesDate = currDate;
		while (seriesDate.after(strDate)) {
			seriesDate = getPreviousDay(currDate);
			// if(!seriesDate.before(strDate)) {
			list.add(getDateFormat(seriesDate, "yyyy-MM-dd"));
			// }
			currDate = seriesDate;
		}
		// list.add(dateStart);
		return list;
	}

	/**
	 * ��õ�ǰ�·ݵĹ�����
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static List<String> getSeriesWorkDayNow(final String dateStr) {
		final List<String> list = new ArrayList<String>();
		final Date currDate1 = parseDateFormat(dateStr + "-" + String.valueOf(dayArray[Integer.parseInt(dateStr.substring(5, 7)) - 1]), "yyyy-MM-dd");
		Date currDate = getFirstDayOfNextMonth(currDate1);
		final int n = getSeriesWorkDayNum(dateStr);
		Date seriesDate = null;
		for (int i = 1; i < n; i++) {
			seriesDate = getPreviousWeekDay(currDate);
			list.add(getDateFormat(seriesDate, "yyyy-MM-dd"));
			currDate = seriesDate;
		}
		return list;
	}

	/**
	 * ��õ�ǰ�·ݵĹ���������
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static int getSeriesWorkDayNum(final String dateStr) {
		final Date currDate1 = parseDateFormat(dateStr + "-" + String.valueOf(dayArray[Integer.parseInt(dateStr.substring(5, 7)) - 1]), "yyyy-MM-dd");
		final Date currDate2 = parseDateFormat(dateStr + "-" + "01", "yyyy-MM-dd");
		final Date currDate = getFirstDayOfNextMonth(currDate1);
		int n;
		if(getCurrentWeek(currDate) < getCurrentWeek(currDate2)) {
			n = dayArray[Integer.parseInt(dateStr.substring(5, 7)) - 1] - 2
			    * (getWeekCountOfYear(Integer.parseInt(dateStr.substring(0, 4))) - getCurrentWeek(currDate2) - 1);
		} else {
			n = dayArray[Integer.parseInt(dateStr.substring(5, 7)) - 1] - 2 * (getCurrentWeek(currDate) - getCurrentWeek(currDate2) - 1) - 1;
		}
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(currDate2);
		if(gc.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || gc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
			n = n - 1;
		}
		final GregorianCalendar gc1 = (GregorianCalendar) Calendar.getInstance();
		gc1.setTime(currDate1);
		if(gc1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || gc1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
			n = n + 1;
		}
		return n;
	}

	public static List<String> getSeriesWorkDay(final String dateStr) {
		return getSeriesWorkDay(dateStr, 5, "yyyy-MM-dd");
	}

	/**
	 * ��õ�ǰ����ǰ������n��
	 * 
	 * @param dateStr
	 * @param n
	 * @param pattern
	 * @return
	 */
	public static List<String> getSeriesDay(final String dateStr, final int n, final String pattern) {
		final List<String> list = new ArrayList<String>();
		Date currDate = parseDateFormat(dateStr, "yyyy-MM-dd");
		list.add(getDateFormat(currDate, pattern));
		Date seriesDate = null;
		for (int i = 1; i < n; i++) {
			seriesDate = getPreviousDay(currDate);
			list.add(getDateFormat(seriesDate, pattern));
			currDate = seriesDate;
		}
		return list;
	}

	public static int[] getSeriesDay(Date startDate, final int nDays) {
		final int[] seriesDays = new int[nDays];
		for (int i = 0; i < nDays; i++) {
			seriesDays[i] = Integer.parseInt(getDateFormat(startDate, "yyyyMMdd"));
			startDate = getPreviousDay(startDate);
		}
		return seriesDays;
	}

	public static int getSpecialDay(final String dateStr) {
		final Date date = parseDateFormat(dateStr, "yyyy-MM-dd");
		return Integer.parseInt(getDateFormat(date, "yyyyMMdd"));
	}

	public static List<String> getSeriesDay(final String dateStr) {
		return getSeriesDay(dateStr, 5, "yyyy-MM-dd");
	}

	public static Date getPreviousDay(final java.util.Date date) {
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		return getPreviousDay(gc);
	}

	public static Date getPreviousDay(final java.util.Calendar gc) {
		gc.add(Calendar.DATE, -1);
		return gc.getTime();
	}

	/**
	 * ���������ڴ��ڿ�ʼ���� ����true ����������С�ڿ�ʼ���� ����false
	 * 
	 * @param souceDate
	 *          ��ʼ����
	 * @param targetDate
	 *          ��������
	 * @return
	 */
	public static boolean timeHasPassed(final String souceDate, final String targetDate) {
		final Date start = parseDateFormat(souceDate, "yyyy-MM-dd HH");
		final Date end = parseDateFormat(targetDate, "yyyy-MM-dd HH");
		final long startTime = start.getTime();
		final long endTime = end.getTime();
		final long value = endTime - startTime;
		if(value >= 0) {
			return true;
		}
		return false;
	}

	public static boolean timeHasPassed(final Date sourDate, final Date targetDate) {
		return timeHasPassed(getDateFormat(sourDate, "yyyy-MM-dd HH"), getDateFormat(targetDate, "yyyy-MM-dd HH"));
	}

	public static final int year(final Date date) {
		return field(date, Calendar.YEAR);
	}

	public static final int month(final Date date) {
		return field(date, Calendar.MONTH);
	}

	public static final int dayOfYear(final Date date) {
		return field(date, Calendar.DAY_OF_YEAR);
	}

	public static final int dayOfMonth(final Date date) {
		return field(date, Calendar.DAY_OF_MONTH);
	}

	public static final int dayOfWeek(final Date date) {
		return field(date, Calendar.DAY_OF_WEEK);
	}

	public static final int hourOfDay(final Date date) {
		return field(date, Calendar.HOUR_OF_DAY);
	}

	public static final int minute(final Date date) {
		return field(date, Calendar.MINUTE);
	}

	public static final int second(final Date date) {
		return field(date, Calendar.SECOND);
	}

	public static final int field(final Date srcDate, final int calType) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(srcDate);
		return cal.get(calType);
	}

	/**
	 * ���ָ����ǰһ���ڼ�
	 */
	public static Date getPreWeekDay(final int weekDay) {
		final Calendar cal = Calendar.getInstance();
		final int wd = cal.get(Calendar.DAY_OF_WEEK);
		if(wd >= weekDay) {
			cal.add(Calendar.DATE, weekDay - wd);
		} else {
			cal.add(Calendar.DATE, weekDay - (7 + wd));
		}
		return cal.getTime();
	}

	public static final int getHour(final Date dateTime) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(dateTime);
		return cal.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * ��ȡָ��������
	 * 
	 * @param date
	 * @param amount
	 * @return
	 */
	public static Date getSpecailDay(final java.util.Date date, final int amount) {
		final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
		gc.setTime(date);
		return getSpecailDay(gc, amount);
	}

	public static Date getSpecailDay(final java.util.Calendar gc, final int amount) {
		gc.add(Calendar.DATE, amount);
		return gc.getTime();
	}

	public static final long getMillisOf(final Date date) {
		return date.getTime();
	}

	public static boolean dateCompare(final Date s1, final Date s2, final Date e1, final Date e2) {
		if(s1 == null || s2 == null || e1 == null || e2 == null) {
			return true;
		}
		if(getMillisOf(s1) >= getMillisOf(e1) && getMillisOf(s2) >= getMillisOf(e2) && getMillisOf(s1) <= getMillisOf(e2)) {
			return true;
		}
		if(getMillisOf(s1) <= getMillisOf(e1) && getMillisOf(s2) >= getMillisOf(e2)) {
			return true;
		}
		if(getMillisOf(s1) <= getMillisOf(e1) && getMillisOf(s2) <= getMillisOf(e2) && getMillisOf(s2) >= getMillisOf(e1)) {
			return true;
		}
		if(getMillisOf(s1) >= getMillisOf(e1) && getMillisOf(s2) <= getMillisOf(e2)) {
			return true;
		}
		return false;
	}

	/**
	 * ������ʱ���֮��ֵ
	 */
	public static int calculateDValue(final Date startDate, final Date endDate, int type) {
		final long start = startDate.getTime();
		final long end = endDate.getTime();
		if(Calendar.SECOND == type) {
			return (int) ((end - start) / SECONDS);
		} else if(Calendar.MINUTE == type) {
			return (int) ((end - start) / MINUTE);
		} else if(Calendar.HOUR == type) {
			return (int) ((end - start) / HOUR);
		} else if(Calendar.DATE == type) {
			return (int) ((end - start) / DAY);
		} else if(Calendar.MONTH == type) {
			return (int) ((end - start) / DAY * 30);
		} else if(Calendar.YEAR == type) {
			return (int) ((end - start) / DAY * 365);
		}
		return -1;
	}

	/**
	 * ������ʱ���֮��ֵ
	 */
	public static int calculateDValue(final Date startDate, int type) {
		return calculateDValue(startDate, new Date(), type);
	}

	/*
	 * �õ����������ƫ��һ���������ܸ�ʽ������
	 */
	public static int getYyyyWwDate(Calendar cal, int offset) {
		cal.add(Calendar.WEEK_OF_YEAR, offset);
		return cal.get(Calendar.YEAR) * 100 + cal.get(Calendar.WEEK_OF_YEAR);
	}

	/**
	 * �ж��Ƿ���ÿ���ĳһʱ��
	 * 
	 * @param type
	 * @param value
	 * @return
	 */
	public static boolean isSomeTime(final int type, final int value) {
		final Calendar cal = Calendar.getInstance();
		if(type == Calendar.HOUR_OF_DAY) return value == cal.get(Calendar.HOUR_OF_DAY);
		else if(type == Calendar.DATE) return value == cal.get(Calendar.DATE);
		else if(type == Calendar.MONTH) return value == cal.get(Calendar.MONTH);
		else if(type == Calendar.YEAR) return value == cal.get(Calendar.YEAR);
		return false;
	}

	public static String[] weekDays = { "������", "����һ", "���ڶ�", "������", "������", "������", "������" };

	public static String getWeekOfDate(final Date dt) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(dt);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if(w < 0) w = 0;
		return weekDays[w];
	}

	/**
	 * ��ȡ���ڶ�����������Ϊ0
	 * 
	 * @return
	 */
	public static Calendar getCalendar(int val) {
		Calendar cal = Calendar.getInstance();
		switch (val) {
		case Calendar.YEAR:
			cal.set(Calendar.MONTH, 0);
		case Calendar.MONTH:
			cal.set(Calendar.DATE, 0);
		case Calendar.DATE:
			cal.set(Calendar.HOUR_OF_DAY, 0);
		case Calendar.HOUR_OF_DAY:
			cal.set(Calendar.MINUTE, 0);
		case Calendar.MINUTE:
			cal.set(Calendar.SECOND, 0);
		case Calendar.SECOND:
			cal.set(Calendar.MILLISECOND, 0);
		}
		return cal;
	}
}
